import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'common/index.dart';
import 'pages/index.dart';

///
///Author: YYF
///Date: 2022-02-06 16:55:34
///Description:全局静态数据
///

class Global {
  /// 初始化
  static Future init() async {
    WidgetsFlutterBinding.ensureInitialized();
    await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
    await ScreenUtil.ensureScreenSize();

    setSystemUi();
    // Loading();

    await Get.putAsync<StorageService>(() => StorageService().init());
    Get.lazyPut(() => UserStore());
    // Get.put(ConfigStore());
    initBaseController();
    if (UserStore.to.hasToken) {
      //极光推送
      // JPushUtils().initPlatformState();
    }
  }

  static initBaseController() {
    Get.lazyPut(() => HomeController());
    Get.lazyPut(() => TaskController());
    Get.lazyPut(() => StationController());
    Get.lazyPut(() => MineController());
    Get.lazyPut(() => ApplicationController());
  }

  static void setSystemUi() {
    if (GetPlatform.isAndroid) {
      //       SystemUiOverlayStyle systemUiOverlayStyle =
      //     const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      // SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);

      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarDividerColor: Colors.transparent,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarIconBrightness: Brightness.dark,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }
}
